package cn.edu.lnsf.controller;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import cn.edu.lnsf.model.Customers;
import cn.edu.lnsf.model.Orders;
import cn.edu.lnsf.model.Waiter;
import cn.edu.lnsf.service.IwaiterService;
import cn.edu.lnsf.service.impl.WaiterServiceImpl;

public class WaiterController {

	// public static List<Orders> listWaiter;
	private IwaiterService service = new WaiterServiceImpl();
	public Waiter w = new Waiter();
	public Scanner scanner = new Scanner(System.in);
	public static String waiterID;
	public String waiterName;
	public String waiterIDCard;
	public String waiterPhone;
	public String remarks;
	public String waiterJoinDate;
	public String waiterBirthday;
	public TimeExtensionController tc = new TimeExtensionController();
	public CustomersController cc = new CustomersController();
	public OrdersController oc = new OrdersController();
	public RoomController rc = new RoomController();

	// 判断ID
	@SuppressWarnings("resource")
	public List<Orders> findWaiterID() {
		System.out.print("\t\t\t\t❤请输入你的服务员ID：");
		Orders ow = new Orders();
		Scanner in = new Scanner(System.in);
		waiterID = in.next();
		ow.setWaiterID(waiterID);
		List<Orders> listWaiter = new ArrayList<Orders>();
		listWaiter.add(ow);
		System.out.println(listWaiter.get(0));
		if (service.findWaiterID(waiterID) == true) {
			System.out
					.println("\t\t\t\t\t\t\t\t      ✪       欢迎登录枫叶酒店...    ✪");
		} else {
			System.out
					.println("\t\t\t\t\t\t\t\t      ✪       服务员ID输入错误...    ✪");
		}
		return listWaiter;
	}

	// public String waiterID(){
	// String id = findWaiterID().get(0).getWaiterID();
	// return id;
	// }

	// 根据服务员ID查找服务员
	public void findWaiter() {
		System.out.print("\t\t\t\t❤请输入需要查找的服务员ID：");
		waiterID = scanner.next();
		service.findWaiter(waiterID);
	}

	// 插入服务员信息
	@SuppressWarnings("unused")
	public void insertWaiter() {
		String waiterID, waiterName, waiterBirthday, waiterIDCard, waiterJoinDate, waiterPhone, remarks;
		System.out.println();
		System.out.println("\t\t\t\t\t        ❤请填写相关信息：");
		System.out.print("\t\t\t\t\t        ❤服务员编号：");
		waiterID = scanner.next();
		System.out.print("\t\t\t\t\t        ❤姓名：");
		waiterName = scanner.next();
		System.out.print("\t\t\t\t\t        ❤身份证号：");
		waiterIDCard = scanner.next();
		System.out.print("\t\t\t\t\t        ❤生日：");
		waiterBirthday = waiterIDCard.substring(6, 10)+"-"+
				waiterIDCard.substring(10, 12)+"-"+waiterIDCard.substring(12, 14);
		System.out.println(waiterBirthday);
//		waiterBirthday = scanner.next();
		System.out.print("\t\t\t\t\t        ❤电话号码：");
		waiterPhone = scanner.next();
		System.out.print("\t\t\t\t\t        ❤备注：");
		remarks = scanner.next();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date Bdate = format.parse(waiterBirthday);
			w.setWaiterBirthday(Bdate);
//			Date Jdate = format.parse(waiterJoinDate);
//			w.setWaiterJoinDate(Jdate);
		} catch (ParseException e) {
			System.out.println("\t\t\t\t\t\t\t\t      ✪       不合法的输入    ✪");
			e.printStackTrace();
		}
		w.setWaiterID(waiterID);
		w.setWaiterName(waiterName);
		w.setWaiterIDCard(waiterIDCard);
		w.setWaiterPhone(waiterPhone);
		w.setRemarks(remarks);
		service.insertWaiter(w);
		System.out.println("\t\t\t\t\t\t\t\t      ✪       插入成功！    ✪");
	}

	// 查找所有的服务员信息
	public void findAllWaiter() {
		service.findAllWaiter();
	}

	// 更新服务员信息
	public void updateWaiter(Waiter w) {
		System.out.println();
		System.out.print("\t\t\t\t\t        ❤请输入需要修改的服务员编号：");
		waiterID = scanner.next();
		System.out.println("\t\t\t\t\t        ❤请输入修改后服务员的信息：");
		System.out.print("\t\t\t\t\t        ❤姓名：");
		waiterName = scanner.next();
		System.out.print("\t\t\t\t\t        ❤生日：");
		waiterBirthday = scanner.next();
		System.out.print("\t\t\t\t\t        ❤身份证号：");
		waiterIDCard = scanner.next();
		System.out.print("\t\t\t\t\t        ❤入职日期：");
		waiterJoinDate = scanner.next();
		System.out.print("\t\t\t\t\t        ❤电话号码：");
		waiterPhone = scanner.next();
		System.out.print("\t\t\t\t\t        ❤备注：");
		remarks = scanner.next();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		try {
			Date Bdate = format.parse(waiterBirthday);
			w.setWaiterBirthday(Bdate);
			Date Jdate = format.parse(waiterJoinDate);
			w.setWaiterJoinDate(Jdate);
		} catch (ParseException e) {
			System.out.println("\t\t\t\t\t\t\t\t      ✪       不合法的输入    ✪");
			e.printStackTrace();
		}
		w.setWaiterID(waiterID);
		w.setWaiterName(waiterName);
		w.setWaiterIDCard(waiterIDCard);
		w.setWaiterPhone(waiterPhone);
		w.setRemarks(remarks);
		service.updateWaiter(w);
		System.out.println("\t\t\t\t\t\t\t\t      ✪       更新成功！    ✪");
	}

	// 删除服务员信息
	public void deleteWaiter(String waiterID) {
		System.out.print("\t\t\t\t❤请输入需删除服务员的编号：");
		waiterID = scanner.next();
		service.deleteWaiter(waiterID);
		System.out.println("\t\t\t\t\t\t\t\t      ✪       删除成功！    ✪");
	}

	public void countProportion() {
		service.countProportion();
	}

	// public static List<Orders> getListWaiter() {
	// return listWaiter;
	// }
	//
	// public List<Orders> setListWaiter(List<Orders> listWaiter) {
	// return WaiterController.listWaiter = listWaiter;
	// }

	@SuppressWarnings("resource")
	public void manage() {
		UserController ct = new UserController();
		Scanner in = new Scanner(System.in);
		int b = 1;
		while (b != 0) {
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆๑۩۞۩๑☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.println("\t\t\t\t\t\t                 1、管理服务员信息");
			System.out.println("\t\t\t\t\t\t                 2、管理顾客信息");
			System.out.println("\t\t\t\t\t\t                 3、管理房间信息");
			System.out.println("\t\t\t\t\t\t                 4、财务管理");
			System.out.println("\t\t\t\t\t\t                 5、管理用户信息");
			System.out.println("\t\t\t\t\t\t                 0、退出");
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.print("\t\t\t\t❤请选择操作数字：");
			int choose = in.nextInt();
			switch (choose) {
			case 1:
				waiter();
				break;
			case 2:
				customer();
				break;
			case 3:
				room();
				break;
			case 4:
				oc.finance();
				break;
			case 5:
				ct.Userview();
				break;
			case 0:
				b = 0;
				System.out.println("\t\t\t\t\t\t\t\t      ✪       退出成功！     ✪");
				break;
			default:
				System.out
						.println("\t\t\t\t\t\t\t\t      ✪       请正确输入:     ✪");
			}

		}
	}


	public void waiter() {
		int choose1 = -1;
		while (choose1 != 0) {
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆๑۩۞۩๑☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.println("\t\t\t\t\t\t                 1、新增服务员");
			System.out.println("\t\t\t\t\t\t                 2、删除服务员");
			System.out.println("\t\t\t\t\t\t                 3、更新服务员");
			System.out.println("\t\t\t\t\t\t                 4、查找全部服务员");
			System.out.println("\t\t\t\t\t\t                 5、根据服务员编号查找服务员");
			System.out.println("\t\t\t\t\t\t                 0、退出");
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.print("\t\t\t\t❤请选择操作数字：");
			choose1 = scanner.nextInt();
			switch (choose1) {
			case 1:
				insertWaiter();
				break;
			case 2:
				deleteWaiter(waiterID);
				break;
			case 3:
				updateWaiter(w);
				break;
			case 4:
				findAllWaiter();
				break;
			case 5:
				findWaiter();
				break;
			case 0:
				break;
			default:
				System.out.println("\t\t\t\t\t\t\t\t      ✪      没有此项选择    ✪");
			}
		}

	}

	public void customer() {
		int choose1 = -1;
		while (choose1 != 0) {
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆๑۩۞۩๑☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.println("\t\t\t\t\t\t                 1、新增顾客");
//			System.out.println("\t\t\t\t\t\t                 2、删除顾客");
			System.out.println("\t\t\t\t\t\t                 2、更新顾客");
			System.out.println("\t\t\t\t\t\t                 3、查找全部顾客");
			System.out.println("\t\t\t\t\t\t                 4、根据顾客身份证查找顾客");
			System.out.println("\t\t\t\t\t\t                 0、退出");
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.print("\t\t\t\t❤请选择操作数字：");
				choose1 = scanner.nextInt();
			switch (choose1) {
			case 1:
				cc.insertCustomers();
				break;
//			case 2:
//				cc.deleteCustomers(null);
//				break;
			case 2:
				Customers c = new Customers();
				cc.updateCustomers(c);
				break;
			case 3:
				cc.findAllCustomers();
				break;
			case 4:
				cc.findCustomersBycustomerIDCard(null);
				break;
			case 0:
				break;
			default:
				System.out.println("\t\t\t\t\t\t\t\t      ✪      没有此项选择    ✪");
			}
		}

	}

	public void room() {
		int choose1 = -1;
		while (choose1 != 0) {
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆๑۩۞۩๑☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.println("\t\t\t\t\t\t                 1、新增房间");
			System.out.println("\t\t\t\t\t\t                 2、删除房间");
			System.out.println("\t\t\t\t\t\t                 3、更新房间");
			System.out.println("\t\t\t\t\t\t                 4、查找全部房间");
			System.out.println("\t\t\t\t\t\t                 5、根据房间号查找房间");
			System.out.println("\t\t\t\t\t\t                 0、退出");
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.print("\t\t\t\t❤请选择操作数字：");
			choose1 = scanner.nextInt();
			switch (choose1) {
			case 1:
				rc.insertintofoRoom();
				break;
			case 2:
				rc.deleteRoom(null);
				break;
			case 3:
				rc.updateRoom();
				break;
			case 4:
				rc.findAllRoom();
				break;
			case 5:
				rc.findRoomByroomNumber(null);
				break;
			case 0:
				break;
			default:
				System.out.println("\t\t\t\t\t\t\t\t      ✪      没有此项选择    ✪");
			}
		}

	}

	public void asd() {
		int choose = 1;
		while (choose != 0) {
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆๑۩۞۩๑☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.println("\t\t\t\t\t\t                 1、预订房间");
			System.out.println("\t\t\t\t\t\t                 2、办理入住");
			System.out.println("\t\t\t\t\t\t                 3、办理退房");
			System.out.println("\t\t\t\t\t\t                 4、续订房间");
			System.out.println("\t\t\t\t\t\t                 5、财务报表");
			System.out.println("\t\t\t\t\t\t                 0、退出");
			System.out.println();
			System.out
					.println("\t\t\t\t\t        ❤☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆❤");
			System.out.println();
			System.out.print("\t\t\t\t❤请选择您需要的服务：");
			int i = scanner.nextInt();
			switch (i) {
			case 1:
				cc.insertintofoCustomers();
				break;
			case 2:
				oc.updateOrderInfo();
				break;
			case 3:
				oc.updateOrderOutfo();
				break;
			case 4:
				tc.insertExtension();
				System.out.println();
				System.out.println("\t\t\t\t\t\t\t  ✪      续订成功！    ✪");
				break;
			case 5:
				oc.finance();
				break;
			case 0:
				choose = 0;
				break;
			default:
				System.out.println("\t\t\t\t\t\t\t\t      ✪      没有此项选择    ✪");
			}

		}

	}

}
